package com.xs.designpattern;

import lombok.extern.slf4j.Slf4j;

/**
 * 代理类
 *
 * @author xs
 */
@Slf4j
public class WizardTowerProxy implements WizardTower {
    /**
     * 限制进入塔内的巫师数量
     */
    private static final int NUM_WIZARDS_ALLOWED = 3;

    /**
     * 记录当前进入塔内的巫师数量
     */
    private int numWizards;

    private final WizardTower tower;

    public WizardTowerProxy(WizardTower tower) {
        this.tower = tower;
    }

    @Override
    public void enter(Wizard wizard) {
        // 检查巫师数量是否达到限制，如果没有达到，允许巫师进入，并增加巫师数量；否则，不允许巫师进入。
        if (numWizards < NUM_WIZARDS_ALLOWED) {
            tower.enter(wizard);
            numWizards++;
        } else {
            log.info("{} 不允许进入!", wizard);
        }
    }
}
